import {fetchChargeCounts} from '@/services/pay/PayCommon';

export default {
  namespace: 'PIndexChargeStatistics',

  state: {
    counts: {
      paidChargeCounts: {
        amount: 0,
        num: 0,
        users: 0,
      },
      unpaidChargeCounts: {
        amount: 0,
        num: 0,
        users: 0,
      }
    },
  },

  effects: {
    * fetchChargeStatisticsCounts({payload}, {call, put}) {
      const response = yield call(fetchChargeCounts, payload);
      if (response.code === 0) {
        yield put({
          type: 'chgCounts',
          payload: response.data,
        });
      }
    },
  },

  reducers: {
    chgCounts(state, action) {
      return {
        ...state,
        counts: action.payload,
      };
    },
  },
};